Fix various issues, get all tests to pass