Performace Improvement: made checking if nodes outputs are inf or nan for efficent