add another termination criterion (not happy with the programmatic solution so far)