Refactor adding data to database