Refactored programm structure