Flatten a deeply nested list