removed some extra loops