Flatten a nested list structure