Moved handler mapping logic from middleware to dispatch