Removed redundant code and optimized some sections