using defer method for returning db instance