Improve stop function