Refactor and flesh out better tests.