Updated endsWith to handle empty strings.