Added state. Needs some more testing