fixed issue with stopping of thread and replaced deprecated api usage