Added sorted functionality based on priority
Added sorted functionality based on priority