Separate the coercion logic to convert middleware.

Closes #34.