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