Refactor database connection system
Merge with fix/get-db