seperating helpful functions from sorting algorithms
full commit