improved function dispatch