added loop function to grid