Changing all instances of *val() functions to typecasts, closes #621