Add statemachine for Documents

it closes #20