Reorder functions such that functions are defined before being used