refactoring codes to function "stopAction"