Rewrite w_graph message interface

Use command queust to send messages to the w_graph worker. This way the worker
should be more reusable. Also makes it possible to remove some duplicate code.