Fixes #85, including test cases