Initial import over from Occam, plus tests