Refactor "uasort" madness in grid computation code