Minor cleanups and performance improvements