Refactoring code and structure