Fixed (#841)

This is a fix for #841 and supporting test.