refactors and adding more query abilities