Auto DB purge fixed, permissions checks were failing. Minor code cleanup