improved speed by removing numpy.any() call