cleanup and fix for #370