Complete code refactoring