Refactoring to prepare for network stuff