Refactor.
Improved test cases.