Make context in flatten() optional