Minor optimizations

- Changing `array.each()` to use a `for` loop instead of a `while` based on http://jsperf.com/array-foreach/2
- Refactored `utility.$()` to have a better decision tree and less wasted ops