Align divergent duplicate js code