clean up and some sanity checks