change in loops so it can run faster