Refactoring in progress. Fixed bug -- need to check for valid user.
More cookie refactoring