added sortBy function