changed forking to allow for output to be produced sorted