Extract dispatch functions.
Add test case.