casting to proper type
scripted update of code from master at e1a6c56 casting to proper type