Working through issues with sorting algorithm, causing some problems elsewhere in the program... This is a non-working version.