Move code out from the actor to reuse it in queries