more refactoring, cleanup