more refactoring. still no threads.