cleanup and performance optimizations