refactoring almost complete. what remains is to fix the last failing unit test and add some more tests to verify special/original use cases