Added error handling to output to Database. Would be worth adding a
better Logger (to a file preferrably)