He moved to Valencia in 1239/40 ( after the fall of Morocco in 1238 ) and continued to work for the sultan there .
He moved 1239 / 40 to Morocco ( after the fall of Valencia in 1238 ) and continued to work for the sultan there .