wq clean state3

Extracts from #268 code not related to the deadlocks.
@dpandiar