some improvements, plus a test method for assigning priority