added code to repair db a bit, and also to delete directories