Fix another little bug in clean_document