Refactor and add additional tests.