Fixing selection sort algorithm