Cookie refresh implemented.
Cleanup and refactor