saving state
Necessary code and xml