Adapted to changes in database API.
Fixed errors and made improvements related to DB API usage.