Fix unit tests

I had a go and fixed all the failing unit tests.