Moving all processing code to top of file