Fixed various oopses, and added extremely basic test suites.