Fixed string sorting function