Refactoring code structure and code itself