Reworked threading
Reformatting