removed old code and started with state-machine