(Rewrite of mapgen2)