Added changes from Alex and Kirbie that they were unable to push due to
Github being bad.  Various fixes to the math and made it much more
readable.