Fixed NaNs resulting from sqrt