Flatten function added.