Enhanced error handling and termination handling

From C-7KDB897