File and reference cleanup