fix potential database errors