Rearranging code to make things run