Refactored. Refined tests.