Remove redundant code from check_structure and rename function to fix_structure