Some refactoring, removal of helper methods.