Fixed some errors in todatabase