Various math changes and fixes