remove document and better state handling