updated with loops