Change $possibleterm to bool, make sure not to reset $completed when $tries is not 0.