refactors states
and removes redundant code
more tweeking of state