Refactoring code structure