output file implemented. now need to sort in proper lexicographical order.