Added support for anonymous users.
Refactoring.