Restructured code to stop unnecessary loading/unloading of stylesheets