Refactored the apphost