add checks for hasOwnProperty and used forEach where useful

when Object.prototype is modified (or Array.prototype, for that matter), we can no longer iterate over the keys (or elements, respectively) using `for (var ... in ...)`. Added a hasOwnProperty check for object key iteration, and used `.forEach` for array element iteration instead.
As a note, `for ... in ...` is bad for performance. Using `Object.keys` and then doing a reverse for loop is preferable