Added authentication and error handling