adding loop functionality