This fixed #3 and added unit tests.