Solving JS performance issues