changed debug output to console.error