js cleanup and bugfix for showing important page multiple times in a row