don't make couch queries inside inner loop