refactor DAO and adding more test cases