more refactoring, pretty clean now