Refactoring to move code into the right place