Fix DB errors

see #156 and fixes #147 and #169