Changing all instances of *val() functions to typecasts, closes #697
merging a2203da3e29534d2776457a97d22fc0faa25c9a8