Modularized the query process