Loop refactored