corrected the corr function loop, moved correlation inside the loop