These two patches address multiple problems in usage of the monitor which lead to a crash on NULL pointer. The first patch fixes all the actual root cause problems. The second patch provides a safety net in case I missed any, or people introduce similar bugs in the future