Refactoring order of functions