Fix flatten function to support arrays