Fixes and hardening for database manipulation.