Add better terminate error handling