Fixed some bugs in making db file