lab5main refactoring