Wrap all close() calls in "ensure" blocks and simplify DB connection-making.