Add type conversion to safediv functions
Fix type computations for statefulapply