fixed ~ subtle type mismatches in new function