performance optimization and cleanup