Moved all the work into subroutines, recovery from temporary files smoother, added parallelisation and memory options to sort.