Fix for issue #20: Cookie authentication is working again.
Refactoring: using early returns where applicable.