Restructured the code