add terminate condition
new, handwritten