Handle NaN data better and do some cleanup