Initial writing to database