Corrected console.log calls to window.console.log.
Using window.console.log throughout to prevent problems with console being undefined.