codes for correlation function