Fixed bug causing sort not to work