refactored some of the correlation code, fixed bugs