source code cleanup and performance optimizations