Refactored for one loop