reworking the structure of the code to support dispatching.