Ensured optimized array usage.  Removed any references to .shift .unshift and .pop.  .push remains where appropriate.