Implemented some perf improvements

@jdimond - Please review and merge:

1. Use `Array.isArray()` instead `Object.prototype.toString.call(location) !== "[object Array]"`.
2. Use `Object.keys().forEach()` to loop through arrays instead of `for var in`.