dao refactored, logic fixed