updating scope in loop