copy from https://github.com/yahoo/dispatchr , later modify these