changed to logical indexing to be consistent when training