Fix #31 and add new test case to reproduce it.