refactor + unittest