unittest impl + refactor