Optimized some parts of the Code