Changing manual calls to loops