Improved the code structure