fixed logout issues; improved thread management