CRM-12942 : added closure for function definition and its usage, as to remove its global definition as mentioned in comment for PR#1059