The indentation here is wrong, the else actually belongs to the outer if statement, not the inner if statement.