Refactor targets and add tests.