Remove dublicated code from js (from merge branch 193)