Various fixes and cleanups