Refactoring code around