Refactor invoker and move some responsibility to function