Refactor message queueing