Add error handling and formatting