Possibly a stupid question, but what happens if totalCnt is 0? I guess the stuff below is skipped since m2n.size is 0? It would be good to add a test for this and maybe just change this test to if(denominator > 0) for clarity.