Refator query codes in DataHandler.