added more secure cookie handling