Refactor to more packages, add pubsub