changing order of functions to make more readable