Why is this code failing the test?