Fix the tests. Also some cleanup