Fix #49 and add a test for it