cleanup and hardened db lookups