Optimize code
Add stop state