Fixes #2 and adds a test for it