Reorganize the code and move the network logic to the engine