refactor database code, separate database creation from CRUD operation