Fix context of custom functions