Fixed (#841)

This is a fix for #841 and supporting test.
So you fixed it, or should modify my PR?