sorting based on priority and parent priority