Put non-public functions into internal.py module. Cleaned up code and
dependencies. Did more documentation.

Next: more documentation, doctest, and testing of the new structure.