[REF] better error checking