Please capitalize where necessary: he served as a jurist in gurganj, was in khwarazm, then was a teacher in gurgan and next an administrator in rayy.
He served as a jurist in Gurganj, was in Khwarazm, then was a teacher in Gurgan and next an administrator in Rayy.