Refactoring and breaking out code