CFY-606 refactor code and added test