updated primary function and added function make_z