Better heuristic / algorithm for shape and id