Fix expected value calculation
Avoid Unnecessary boxing
Split out some duplicate code - also figure out something else about Java