Database fixes/code cleanup