Executing queries and fetching results