added some sanity checking