Added "Stop" button functionality. More code cleanup.