updated to fully functional LOOP