Moved hub code into library, as it is ready to be used in more than one place