added flag to run only on selected elements instead of all