simpler approach with explicit loop