updated database class, should be tested. Perhaps some logging should be added?