_.invert changed iteration to use while loop
optimized _.isElement