Refactoring a lot of the P5 stuff.