CFY-1574 bug fix and add tests