fixed database connection and refresh bugs