updated to fix for loops