Added console.log statements to improve debugging.