Something wrong with calculation and table generation