Added db and some logic