Add loop functionality