Made cleanup more robust