fixing bug where I was checking hasOwnProperty on the wrong element