More sanity checks and cleanup