Checking for topological errors and fixing them