implemented final sort algorithm, nothing tested as of yet