Fixed a bug that could cause incorrect sorting