implement map generator, fix some bugs