Cleanup and optimizations