Refactor loop into psthcorr() function