Misc performance improvements

Miscellaneous fixes and performance improvements