fixing issue with loops