P: working version of acf_n