added general n-dimensional xcorr and refactored 2d xcorr to use it