Fixed some errors

Ensured that database is not created multiple times.