fix math bugs