Refactoring and test
Fix invalid arguement exception
Check cookie name and tests