refactoring code structure