Various fixes and cleanups.