Fixed some crash issues in app delegate