various fixes and cleanup