CFY-1433 start adding tests and fix some bugs