working prototype. still needs test suites, better error messages, and subsequent refactoring