refractored all functions to use pure tag dispatching