Add check for empty priority list and refactor tests.