Minor library changes, fixed thread shutdown bug