isTerminal function done