Added vectorization and logical indexing