optmized: used logical indexing instead of find