Fixed ordering of functions. All functions are now in order from top to bottom as they are called for the first time