Refactoring of a small function