functions (from comments).
Doc-string-ified the lead comments. Added auto call of test() when run as script.
modules only when needed