better input type casting and NaN handling for js client