refactor code for recording