add type inference for nested function and value