Fixed all tests, found minor errors in the process