Add functionality for writing to database