Added code to determine stage of recording