optimized code for functionWrapper