added isnan check