Added robustness to calculateStatistics