Fix several miscalculations