Fixed bug in endsWith() function