More flexible fix for the flatten bug.