Vectorization of crashy code

I'm sorry I didn't bother to do any further cleanup, but I have been debugging occasional crashes on TOC for a week now. This seems to fix it.