Small refactoring + Unit tests