Functional, writes to db