added min and max functions