The final version with session by cookies and fixed aunthefication