refactored code for sql queries of grid data, hpms data from grid_merge repo