refactor in terms of UF data structure
grid and UF data structures