various fixes and cleanups