defensive checks to avoid as yet unexplained crashes