Cleaning up document structure