Changed code AGAIN (facepalm). Just went with a simple foreach.