refactoring

store queries in database