Fixed a bug with the rest headers and cookies
Refactoring