fix cleanup of stack