Cleanup and documentation (doctest)