Fix cleanup logic