Netcode refactor, and a few other fixes