Fixed Sample2
Fixed threading leak issues
Added sample 5 to verify the correctness of the leak fix