Added some console.logs to better see what's going on.