Refactored dispatcher module as per the comments