Refactor for Database connection and manipulations