Improve logic for republishing a changed document