moved all the db logic out of main and to the corresponding class