moved dispatching code to dispatcher