much of the math is written (UNTESTED)