Very confusing results. Added a few more console logs, and changed a bit of code