Refactor and add tests for the component.

Fixes #21.