Structure reorganization, error correction and code refactoring