refactoring, cleanup and coverage