added recording logic