Improved security in set period function