Modifications to LastIndexOf to improve performance.