Writing to file added and sorting arrays to be added.