Fix #983
Add tests for #983 fix