Updated for error handling