add debug function

replace all occurrences of 'console.log' with 'debug'