Check if local key exists before trying to sort