fixed some errors in the db layer