cleanup
fixed bug in state handling