add: threads, some code cleanup