Added error handling