Improved the code implementation.