Break out common code and fix app