updated endsWith function