implemented min-max-element function