Fix #52 and add unit test.