more unit tests working, more refactoring