More refactoring plus unit tests completed

rm