Refactor of a function