Improve robustness of correlation calculations

Introduces additional error handling for correlation and added tests to verify this.

As part of this work, a helper function was introduced to create property accessor functions.

An ErrorContainer was also introduced, in order to allow error and warnings to be passed back to the user.

Finally the average calculations, performed by <code>grouping</code>, were improved to handle taking the average of optional properties.