added button logic to stop recording and terminate program