removing log and better undefined check