Reimplemented LastIndexWhere to make it more efficient