Refactored code to query data in modular methods