added exception handling and logging