Initial javascript logic