refactoring & tests