cleanup and optimizations