Misc fixes and code cleanups.