Added test instructions.
Numerous bug fixes and added doctest.