Fixed some bugs in the database creation code.