fix crash in background mode