another round of code review fixes. Includes much improved tests, cleanup to meet Python coding standards, and improved handling of optional arguments