Refactored the functionality to execute SQL queries.