added errorhandler and fixed authentication