Fixed minor issue with key sorting