Fixes for #297
and added test cases
Fixes for #297 and
added review comment