Fixed tests

These changes get most of the unit tests passing.