Some various fixes and cleanup