Database fixes and cleanup.