enhanced error handling in guard thread