Significant refactoring and other changes.  Now nearly RFC 7089 compliant.