Performance code refactoring