Various fixes. Getting unit tests to pass.