Fix bug where rotating device crashes app