fixes #25 and adds unit test