switched to splicing over array swapping (splicing much more efficient in JS)