fix data races in controller

Fix #305
Sure. This is an easy change.