added some console logs for clarity