Massive refactor, and some packet work