sorting and comparisons working but using wrong technique