cleanups plus more sanity checks