refactoring
yet more refactoring, hopefully done for now