Fixed it. More or less.

Note to self - Element arrays start at 0 you fucking moron.