Some minor cleanups and optimizations