fixed NaNing and (maybe) infinities, seems stableish but still needs fixing