Fix potential crash when executing in background