added function min and stuff