add functionality to deal with nan