Add tests for empty datasets and patch logic/math to properly handle them