clean up and optimizations