Create function and add loop