Cleanup and optimizations stuff