This finally block seems to be very similar (maybe equal?) to the one in doQuery... Maybe it could be factorized in a common function?