Tidying up index javascript