fixing issue with traversing the object tree

I fixed the issue, my bad. I was checking the hasOwnProperty for the wrong element.