Adding hasOwnProperty in all the for in loops to prevent errors on prototype overloading