private Pair<Double, Double> improveMaximum(NegativeSymmetricList r, int offset, int nx, int ixmid,
            int interpolation) {
        if (ixmid <= 1) {
            double ixmid_real = 1;
            return new Pair<Double, Double>(r.get(offset + 1), ixmid_real);
        }

        if (ixmid >= nx) {
            return new Pair<Double, Double>(r.get(nx + offset), (double) nx);
        }
        if (interpolation <= NUM_PEAK_INTERPOLATE_NONE) {
            return new Pair<Double, Double>(r.get(ixmid + offset), (double) ixmid);
        }

        if (interpolation == NUM_PEAK_INTERPOLATE_PARABOLIC) {
            double dy = 0.5 * (r.get(ixmid + 1 + offset) - r.get(ixmid - 1 + offset));
            double d2y = 2 * r.get(ixmid + offset) - r.get(ixmid - 1 + offset) - r.get(ixmid + 1 + offset);
            double ixmid_real = ixmid + dy / d2y;
            return new Pair<Double, Double>(r.get(ixmid + offset) + 0.5 * dy * dy / d2y, ixmid_real);
        }

        // Sinc interpolation
        int depth = interpolation == NUM_PEAK_INTERPOLATE_SINC70 ? 70 : 700;
        Pair<Double, Double> brent_results = minimizeBrent(r, offset, depth, nx, ixmid - 1, ixmid + 1, 1e-10);
        double ixmid_real = brent_results.first;
        return new Pair<Double, Double>(-brent_results.second, ixmid_real);
    }