Adding comments and cleaning up the code for isElementPresent