fix bug in db building