streamlining code/mistakes with js