did some cleanup in loops and whatnot