refactored two functions to utils