add database reconnection code and create database tables if they aren't there