code refine for query data from contract