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