bug fixes and finishing up documentation
actually writing tests finally. far too late.

many of the bug fixes in the previous commit came from
these tests failing. they are currently all passing and should
be correct.