still buggy with min & max values for range

added answer from the stack overflow