Crash fix on app exit