Added loop functionality, tests