Fixing:toLowerCase of undefined error