Refactoring, better memory usage