Major changes in the code combined with its optimization