Better error handling and authentication improvements