Improve isElement function