Error handling and loggig