Various math fixes