Broke up defragGrid() into multiple functions to make figuring this thing out easier.