Rearranging uses objects instead of arrays for looking up elements, should be faster. Needs debugging.