Refactors.

Refactor code to facilitate using rabbitmq instead of threading queue.