Cleanups and performance improvements