Refactoring and first test functions