merged some of the refactorings from the undorefactoring branch