Prevent bad crashes when app goes background