code cleanup + threading testing