fixed bugs, and emergency stop