Added loop functionality