This loop should be more cleanly written.