Fix can't read length of undefined error.