How to make the perfect loop