problem with sort function, If conditional not working.