Simplified and added some locks
Use channels to send messages