fix two RuntimeExceptions that occur in very rare situations.
fix some other RuntimeExceptions