Some optimizations in db classes.