Fix type inference for functions