re-order priority and construct functions according to priority.