Fix for issue #19 + tests (I think)