Fix undefined variable warning and remove console.log