moved connection to database to other method