more refactoring, still looks bad