Several bug fixes needed to get the tests to run