Complete code refactoring to gain more performance.