fixed inf/nan bug