code cleanup and switching back to threads