Fix a few common crashes

Change-Id: Icd2322a4f7bc18fe0f475361f00ada076f575c3f