Added more unit tests

Changed code to be more testable.
See issue #47