Implemented OOP way. Todo correct therad ending