Added clear function to be called at the completion of a when statement