Fixed index out of bounds bug, i think. Test!