Refactoring to tests