fix cleanup in agent