removed one loop in the function period()