Remove duplicate funcction
Adjust function
Move more javascript out of templates
Merge