javascript refactoring and fixing of broken links