refactor Stop() function for better use outside package