Retooled the state package, commented, and abstracted a LOT.