implemented the db logic