Moved assignments to top of function