Refactored hosting code to be completely self contained