Refactoring function
Unit Test