Fixed a bug in correlation function