CFY-1184 bug fix and refactoring