Cleaned up db connection code