Minor speed improvements:
* use concat() instead of slice() to copy arrays
* Instantiate array using [] instead of new Array()
* Hoist array lengths in for loops where appropriate
* Cleaned up imports