DAO refactoring and test fixes