Move to self-calling function and remove monkey patching of Array prototype

The big thing here is removal of the monkey patching for the array prototype and moving them to internal utility functions.  This is simply to help avoid any issues with any code that maybe doing something similar with the Array prototype.

Also moved the code into a self calling function, for cleanliness more than anything.