Moved database connect to separate function