Adding loop functionality