fully working loop