Optimizing bases_match