Updated with thread implementation