Refactor Quantile to avoid bug.

There was a bug in quantile causing it to return some percentiles that
were below the min value. This simplifies quantile and adds some sanity
tests to ensure we don't get this behaviour.

Review @dwhjames