add ai priority and rearrange func