Fix error and failure in tests