Re-wrote the function wrapping code to clean it up and re-added the wrapFunction.