Fix some duplication in js