Refactor
Adding write to database