Moved declarations of variables around

What I really want to do is figure out how to exit this function