add generatelastlevel function.