fix statement ordering so that set gets cleared properly