Fix bug for db connection
Fix bug for db connection
Add more testing and fixes