Fix crashing on backgrounding.