Some more refactorings to prepare for networking