js works but insanely slow