Typeof fix for undefined check