#781 - refactoring mostly done, updating tests