Added exceptions to the database connection and updated log levels
Added more error  checking and refactored sqlite code