fixed loops bug