added console.log and some explanation comments