Fix duplication in javascript