Add db maintenance routine. Move cleanup functions to maintenance module.