sanity checks and error catching