Gh 1204

tested locally and updated test cases. ready for merge.