added code to upgrade the database along with initializing a new one.
added more error logging
code formatting