Added and integrarted stack overflow detection and recovery