PUD: move state code into its own source files