Refactor DAO layer in a more generic way.