Separating into two functions, record and playback. Individually called in main.