Fix bug in cleaning up