moved some code around

Change-Id: I91a65aeed330a3565f9be28c67e8b84ff1f6bae9