Added functional tests; made authentication a bit more resilient to errors