Properly check for null.
Apply database batches in smaller packages.

- Reduce size of a transaction to avoid interaction cache overflows.
- Created DBUtils.applyInSmallBatches helper.
Formatting.