updated priority algorithm