Improved session and flash cookie encoding