Added tests, improved authentication