some cleanups and performance optimizations