modify countNodes & countRelationships to be more memory efficient