Implement proper saving of paste data to database and preserve history