Added a test framework and fixed errors found by running this test