some cleanups and robustness checks, I added while searching for a bug (that was...