Merge branch 'cast-value'

* small improvements to cast_value()