Fixed issue with writing to sessions