fixed the name sorting function