Simplify and improve freep().