Change output name from 'corr.diff' to 'diff.corr'; add unit test; improve a few conditional statement