complete rewrite to use dictionary representation with tuples coords as keys instead of list of lists