Move functions to bottom

moved main code to top