Remove unneeded imports
Abstract out the when (isJust foo) $ ... fromJust foo pattern