Fix random errors for tests