ExternalFunc, more type inference

Also working on type casting