Code refactor and minimal modify tests.