Changed functions to closures to prevent naming conflicts

Circumvention of the problem caused by redefinition of functions