restructured the code