refactoring of def code