Improved structure of the code