updated cleanup task logic