more refactoring, code cleanup