Refactored ctor and method defining to share more code.
Properly infer type of lambda when emitting function calls.