cleanup and performance improvements