some more refactoring, code cleanup