less duplicated code in queries logic