Got rid of a nasty loop now that I found the right way to do things.