implemented min-max, but buggy