small bug in terminal node check