Add checkings for database. Fixes #385