refactoring in progress
more refactoring in progress (test fails)
more unit tests and cleaned a bit better error handling