AI Reimplement sort