Fix unit tests

These changes get all the test specs passing.
It also cleans up some linter warnings in the main code.