Refactoring Dao Layer and fixing tests