added some debug and sanity checks