updated to faster query/count method