Fix check for length on undefined object error.