Moved doubled js code to separate file