safer error checking