Done: function for recording data
Done: some cleanup