fixed sorting routine with selection sort