add exception handling and logging