Some DB optimizations. Addresses Issue #29