Deep refactoring performed. Most threading issues fixed.