original acorr function by Adam