Code cleanup and performance improvements.