Prepare functions to handle stop event