added DAO and fixed some bugs