Some performance improvements for the last commit