Refactor the result query into a separate class to handle the cursor
closing issue