Hi,
Your above statements are very confusing.
Are you sure the two code which I provided are causing issues on your site.
Because I don't think these code can cause above stated issues.
So Please remove those two code and check above all issues and share here if you still face the issue or not.
Please point down your issues one by one and with any recording if possible.