Improved code in sortJSONBy function and also improved naming