fixing some math errors