refactoring of assignament 5