fixed thread context saving