Turned "shouldTerminate" into a proper function.