Cleanup and optimization