working version with distributed architecture