Implemented min and max functions