This should fix the crashes

Updated to Thommie's branch