Performance improvements and code cleanups.