fix table and calculation bugs