$val bug

Fixed $val bug resulting in NaN output